﻿using Api.Shared.Model.Common;
using Api.Shared.Model.Dto;
using Api.Shared.Model.Fafu;
using AutoMapper;

namespace Api.Shared.Sugar.Profiles
{
    public class MemberProfile : Profile
    {
        public MemberProfile()
        {
            //源,目标
            CreateMap<Device, DeviceDto>()
                .ForMember(dest => dest.DevicePhoto, opt => opt.MapFrom(src => MapDevicePhoto(src.DevicePhoto)))
                .ForMember(dest => dest.DevicePhotoUrl, opt => opt.MapFrom(src => MapDevicePhoto(src.DevicePhotoUrl)))
                ;

            CreateMap<ParamFengtousMysql, ParamFengtouDto>()
                .ForMember(
                    dest => dest.FengtouPhoto,
                    opt => opt.MapFrom(src => MapDevicePhoto(src.FengtouPhoto))
                )
                .ForMember(
                    dest => dest.FengtouPhotoUrl,
                    opt => opt.MapFrom(src => MapDevicePhoto(src.FengtouPhotoUrl))
                );

            CreateMap<ParamFengtouDto, ParamFengtousMysql>()
                .ForMember(
                    dest => dest.FengtouPhoto,
                    opt => opt.MapFrom(src => string.Join(",", src.FengtouPhoto))
                )
                .ForMember(
                    dest => dest.FengtouPhotoUrl,
                    opt => opt.MapFrom(src => string.Join(",", src.FengtouPhotoUrl))
                );
        }

        private string[]? MapDevicePhoto(string devicePhoto)
        {
            return devicePhoto?.Split(',');
        }
    }
}
